﻿package mortal.game.view.friend
{
    import Message.Game.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.menu.*;
    import mortal.game.view.friend.data.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class FriendSetPanel extends BaseWindow
    {
        private var _findPlayerLabel:GTextFiled;
        private var _findInput:GTextInput;
        private var _searchBtn:GButton;
        private var _splitLine:ScaleBitmap;
        private var _roleNameInfo:FriendSetInfoSpr;
        private var _roleLevelInfo:FriendSetInfoSpr;
        private var _roleCareerInfo:FriendSetInfoSpr;
        private var _roleCombatInfo:FriendSetInfoSpr;
        private var _vipStateInfo:FriendSetInfoSpr;
        private var _sexInfo:FriendSetInfoSpr;
        private var _onlineStateInfo:FriendSetInfoSpr;
        private var _signInfo:FriendSetInfoSpr;
        private var _addFriend:GButton;
        private var _sendPrivateChat:GButton;
        private var _pushToBlack:GButton;
        private var _checkBox_1:GCheckBox;
        private var _checkBox_2:GCheckBox;
        private var _rejectStrange:GTextFiled;
        private var _rejectDisturb:GTextFiled;
        private var _okBtn:GButton;
        private var _cancelBtn:GButton;
        private var _infoList:Vector.<FriendSetInfoSpr>;
        private var _searchRole:SMiniPlayer;
        private var _roleNameStr:String;

        public function FriendSetPanel()
        {
            this._infoList = new Vector.<FriendSetInfoSpr>;
            this.init();
            this.layer = LayerManager.windowLayer;
            return;
        }// end function

        private function init() : void
        {
            setSize(315 + 8, 338 - 12);
            title = Language.getString(41244);
            this.isHideDispose = false;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(8, 41 - 7, 292 + 19, 181, this));
            this._findPlayerLabel = UIFactory.gTextField(Language.getString(41245), 28, 42, 65, 20, this);
            this._findInput = UIFactory.gTextInput(94, 39, 152, 26, this);
            this._searchBtn = UIFactory.gButton(Language.getString(41246), 249, 40, 42, 24, this);
            this._splitLine = UIFactory.bg(12, 71, 288, 1, this, ImagesConst.SplitLine);
            this._roleNameInfo = UICompomentPool.getUICompoment(FriendSetInfoSpr);
            this._roleNameInfo.label = Language.getString(41247);
            this._roleNameInfo.setWidth(120);
            this._roleNameInfo.x = 28;
            this._roleNameInfo.y = 81;
            this.addChild(this._roleNameInfo);
            this._infoList.push(this._roleNameInfo);
            this._roleLevelInfo = UICompomentPool.getUICompoment(FriendSetInfoSpr);
            this._roleLevelInfo.label = Language.getString(41248);
            this._roleLevelInfo.x = 28;
            this._roleLevelInfo.y = 81 + 26;
            this.addChild(this._roleLevelInfo);
            this._infoList.push(this._roleLevelInfo);
            this._roleCareerInfo = UICompomentPool.getUICompoment(FriendSetInfoSpr);
            this._roleCareerInfo.label = Language.getString(41249);
            this._roleCareerInfo.x = 28 + 180;
            this._roleCareerInfo.y = 81 + 26;
            this.addChild(this._roleCareerInfo);
            this._infoList.push(this._roleCareerInfo);
            this._roleCombatInfo = UICompomentPool.getUICompoment(FriendSetInfoSpr);
            this._roleCombatInfo.label = Language.getString(41250);
            this._roleCombatInfo.x = 28;
            this._roleCombatInfo.y = 81 + 26 * 2;
            this.addChild(this._roleCombatInfo);
            this._infoList.push(this._roleCombatInfo);
            this._vipStateInfo = UICompomentPool.getUICompoment(FriendSetInfoSpr);
            this._vipStateInfo.label = Language.getString(41251);
            this._vipStateInfo.x = 28 + 180;
            this._vipStateInfo.y = 81 + 26 * 2;
            this.addChild(this._vipStateInfo);
            this._infoList.push(this._vipStateInfo);
            this._sexInfo = UICompomentPool.getUICompoment(FriendSetInfoSpr);
            this._sexInfo.label = Language.getString(41252);
            this._sexInfo.x = 28;
            this._sexInfo.y = 81 + 26 * 3;
            this.addChild(this._sexInfo);
            this._infoList.push(this._sexInfo);
            this._onlineStateInfo = UICompomentPool.getUICompoment(FriendSetInfoSpr);
            this._onlineStateInfo.label = Language.getString(41253);
            this._onlineStateInfo.x = 28 + 180;
            this._onlineStateInfo.y = 81 + 26 * 3;
            this.addChild(this._onlineStateInfo);
            this._infoList.push(this._onlineStateInfo);
            this._signInfo = UICompomentPool.getUICompoment(FriendSetInfoSpr);
            this._signInfo.label = Language.getString(41254);
            this._signInfo.setWidth(235);
            this._signInfo.x = 28;
            this._signInfo.y = 81 + 26 * 4;
            this.addChild(this._signInfo);
            this._infoList.push(this._signInfo);
            this._addFriend = UIFactory.gButton(Language.getString(41255), 53, 186 + 32, 61, 22, this, "GreenLinkButton");
            this._addFriend.visible = false;
            this._sendPrivateChat = UIFactory.gButton(Language.getString(41256), 131, 186 + 32, 61, 22, this, "GreenLinkButton");
            this._sendPrivateChat.visible = false;
            this._pushToBlack = UIFactory.gButton(Language.getString(41257), 210, 186 + 32, 70 + 10, 22, this, "GreenLinkButton");
            this._pushToBlack.visible = false;
            this._addFriend.configEventListener(MouseEvent.CLICK, this.onTextClickHandler);
            this._sendPrivateChat.configEventListener(MouseEvent.CLICK, this.onTextClickHandler);
            this._pushToBlack.configEventListener(MouseEvent.CLICK, this.onTextClickHandler);
            this._checkBox_1 = UIFactory.checkBox("", 24, 244, 19, 19, this);
            this._checkBox_2 = UIFactory.checkBox("", 24, 267, 19, 19, this);
            this._rejectStrange = UIFactory.gTextField(Language.getString(41258), 47, 244, 130, 22, this);
            this._rejectDisturb = UIFactory.gTextField(Language.getString(41259), 47, 267, 130, 22, this);
            this._okBtn = UIFactory.gButton(Language.getString(41260), 94, 297, 69, 22, this);
            this._cancelBtn = UIFactory.gButton(Language.getString(41261), 172, 297, 69, 22, this);
            this.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            if (ClientSetting.local.getIsDone(IsDoneType.RefuseStranger))
            {
                this._checkBox_1.selected = true;
            }
            else
            {
                this._checkBox_1.selected = false;
            }
            if (ClientSetting.local.getIsDone(IsDoneType.RefuseOtherApply))
            {
                this._checkBox_2.selected = true;
            }
            else
            {
                this._checkBox_2.selected = false;
            }
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_2:String = null;
            if (event.target == this._okBtn)
            {
                if (this._checkBox_1.selected == true)
                {
                    ClientSetting.local.setIsDone(true, IsDoneType.RefuseStranger);
                }
                else
                {
                    ClientSetting.local.setIsDone(false, IsDoneType.RefuseStranger);
                }
                if (this._checkBox_2.selected == true)
                {
                    ClientSetting.local.setIsDone(true, IsDoneType.RefuseOtherApply);
                }
                else
                {
                    ClientSetting.local.setIsDone(false, IsDoneType.RefuseOtherApply);
                }
                this.hide();
            }
            else if (event.target == this._cancelBtn)
            {
                this.hide();
            }
            else if (event.target == this._searchBtn)
            {
                _loc_2 = this._findInput.text;
                if (_loc_2 == "")
                {
                    MsgManager.showRollTipsMsg(Language.getString(41262));
                }
                else
                {
                    _loc_2 = _loc_2.replace(/\s""\s/g, "");
                    this._roleNameStr = _loc_2;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FriendSearch, [_loc_2]));
                }
            }
            return;
        }// end function

        private function onTextClickHandler(event:MouseEvent) : void
        {
            var _loc_2:String = null;
            if (event.target == this._addFriend)
            {
                _loc_2 = this._roleNameInfo.value;
                if (_loc_2 != "")
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FriendApply, _loc_2));
                }
            }
            if (event.target == this._sendPrivateChat)
            {
                PlayerMenuConst.Opearte(PlayerMenuConst.ChatPirvate, this._searchRole);
            }
            if (event.target == this._pushToBlack)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AddToBlackList, this._searchRole));
            }
            return;
        }// end function

        public function updateData(param1:Object) : void
        {
            var _loc_2:SMiniPlayer = null;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:FriendSetInfoSpr = null;
            var _loc_6:FriendSetInfoSpr = null;
            if (param1)
            {
                _loc_2 = param1 as SMiniPlayer;
                if (_loc_2.name != this._roleNameStr)
                {
                    return;
                }
                this._roleNameInfo.updateValue(_loc_2.name);
                this._roleLevelInfo.updateValue(_loc_2.level + Language.getString(41263));
                this._roleCareerInfo.updateValue(GameDefConfig.instance.getECareer(_loc_2.career).text);
                if (_loc_2.sex == 0)
                {
                    this._sexInfo.updateValue(Language.getString(41264));
                }
                else
                {
                    this._sexInfo.updateValue(Language.getString(41265));
                }
                if (!_loc_2.online)
                {
                    this._onlineStateInfo.updateValue(Language.getString(41266));
                }
                else
                {
                    this._onlineStateInfo.updateValue(Language.getString(41267));
                }
                this._roleCombatInfo.updateValue("" + _loc_2.combat);
                if (_loc_2.VIP > 0)
                {
                    this._vipStateInfo.img = GameDefConfig.instance.getVipLevelIconUrl(_loc_2.VIP);
                }
                else
                {
                    this._vipStateInfo.img = "";
                }
                this._signInfo.updateValue(_loc_2.signature);
                if (_loc_2.signature == "")
                {
                    this._signInfo.updateValue(Language.getString(40004).substr(3));
                }
                switch(_loc_2.online)
                {
                    case 0:
                    {
                        for each (_loc_5 in this._infoList)
                        {
                            
                            _loc_5.isGray = true;
                        }
                        break;
                    }
                    case 1:
                    {
                        for each (_loc_5 in this._infoList)
                        {
                            
                            _loc_5.isGray = false;
                        }
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                _loc_3 = _loc_2.entityId.id;
                _loc_4 = Cache.instance.role.playerInfo.playerId;
                if (_loc_3 == _loc_4)
                {
                    this._addFriend.visible = false;
                    this._sendPrivateChat.visible = false;
                    this._pushToBlack.visible = false;
                }
                else
                {
                    this._addFriend.visible = true;
                    this._sendPrivateChat.visible = true;
                    this._pushToBlack.visible = true;
                }
                if (_loc_2.online == 1 && !this.isFriendOrBlack(_loc_3, 0) && _loc_3 != _loc_4)
                {
                    this._addFriend.filters = [];
                    this._addFriend.mouseEnabled = true;
                }
                else
                {
                    this._addFriend.filters = [FilterConst.colorFilter2];
                    this._addFriend.mouseEnabled = false;
                }
                if (_loc_2.online == 1 && !this.isFriendOrBlack(_loc_3, 1) && _loc_3 != _loc_4)
                {
                    this._sendPrivateChat.filters = [];
                    this._sendPrivateChat.mouseEnabled = true;
                }
                else
                {
                    this._sendPrivateChat.filters = [FilterConst.colorFilter2];
                    this._sendPrivateChat.mouseEnabled = false;
                }
                if (!this.isFriendOrBlack(_loc_3, 1) && _loc_3 != _loc_4)
                {
                    this._pushToBlack.filters = [];
                    this._pushToBlack.mouseEnabled = true;
                }
                else
                {
                    this._pushToBlack.filters = [FilterConst.colorFilter2];
                    this._pushToBlack.mouseEnabled = false;
                }
            }
            else
            {
                for each (_loc_6 in this._infoList)
                {
                    
                    _loc_6.clear();
                }
                this._addFriend.visible = false;
                this._sendPrivateChat.visible = false;
                this._pushToBlack.visible = false;
                MsgManager.showRollTipsMsg(Language.getString(41268));
            }
            return;
        }// end function

        private function isFriendOrBlack(param1:int, param2:int) : Boolean
        {
            var _loc_4:SFriendRecord = null;
            var _loc_3:Array = [];
            if (param2 == 0)
            {
                _loc_3 = Cache.instance.friend.friendList;
            }
            else
            {
                _loc_3 = Cache.instance.friend.blackList;
            }
            for each (_loc_4 in _loc_3)
            {
                
                if (param1 == _loc_4.friendPlayer.entityId.id)
                {
                    return true;
                }
            }
            return false;
        }// end function

        public function clear() : void
        {
            var _loc_1:FriendSetInfoSpr = null;
            this._findInput.text = "";
            for each (_loc_1 in this._infoList)
            {
                
                _loc_1.clear();
            }
            this._addFriend.visible = false;
            this._sendPrivateChat.visible = false;
            this._pushToBlack.visible = false;
            return;
        }// end function

        public function get searchRole() : SMiniPlayer
        {
            return this._searchRole;
        }// end function

        public function set searchRole(param1:SMiniPlayer) : void
        {
            this._searchRole = param1;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            var _loc_2:FriendSetInfoSpr = null;
            super.disposeImpl(param1);
            for each (_loc_2 in this._infoList)
            {
                
                _loc_2.dispose(param1);
                _loc_2 = null;
            }
            this._infoList.length = 0;
            this._findPlayerLabel.dispose(param1);
            this._findInput.dispose(param1);
            this._searchBtn.dispose(param1);
            this._splitLine.dispose(param1);
            this._addFriend.dispose(param1);
            this._sendPrivateChat.dispose(param1);
            this._pushToBlack.dispose(param1);
            this._checkBox_1.dispose(param1);
            this._checkBox_2.dispose(param1);
            this._rejectStrange.dispose(param1);
            this._rejectDisturb.dispose(param1);
            this._okBtn.dispose(param1);
            this._cancelBtn.dispose(param1);
            this._findPlayerLabel = null;
            this._findInput = null;
            this._searchBtn = null;
            this._splitLine = null;
            this._addFriend = null;
            this._sendPrivateChat = null;
            this._pushToBlack = null;
            this._checkBox_1 = null;
            this._checkBox_2 = null;
            this._rejectStrange = null;
            this._rejectDisturb = null;
            this._okBtn = null;
            this._cancelBtn = null;
            return;
        }// end function

    }
}
